﻿using System;
#if SILVERLIGHT
using System.Windows.Data;
#else
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml;
#endif

namespace Microsoft.PlayerFramework
{
    /// <summary>
    /// IValueConverter implementation to compare the value with the parameter and return a Visibility enum based on the result.
    /// True = Visible, False = Collapsed
    /// </summary>
    public class ConditionalVisibilityConverter : IValueConverter
    {
        /// <inheritdoc /> 
#if SILVERLIGHT
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
#else
        public object Convert(object value, Type targetType, object parameter, string culture)
#endif
        {
            bool result;
            if (parameter.GetType() == value.GetType())
            {
                result = value == parameter;
            }
            else
            {
                result = value.ToString() == parameter.ToString();
            }
            return result ? Visibility.Visible : Visibility.Collapsed;
        }

        /// <inheritdoc /> 
#if SILVERLIGHT
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
#else
        public object ConvertBack(object value, Type targetType, object parameter, string culture)
#endif
        {
            throw new NotImplementedException();
        }
    }
}
